package com.compton.UI
{
	import com.compton.EVENT.NavigationEvent;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import libs.MultiControl;
	
	public class ControlPanel extends MultiControl
	{
		private var _dir:int = -1;
		
		public function ControlPanel()
		{
			super();
			setUp();
		}
		
		//sets up the controler for multi control and adds event listenrs for all functionality.
		private function setUp():void
		{
			this.stop();
			this.multiControl.tabBtn.addEventListener(MouseEvent.CLICK, onUp);
			this.multiControl.tabBtn.buttonMode = true;
			this.multiControl.findBtn.addEventListener(MouseEvent.CLICK, onFind);
			this.multiControl.wineBtn.addEventListener(MouseEvent.CLICK, onSearch);
		}
		
		//after clicking the tab the direction will be changed and the enter frame will do all of the work.
		private function onUp(evt:MouseEvent):void
		{
			if(_dir == -1)
			{
				_dir = 1;	
				
			}else if(_dir == 1)
			{
				_dir = -1;	
				
			}
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		//dispatches the go2favorite event and moves the panel accordingly
		private function onFind(evt:MouseEvent):void
		{
			
			dispatchEvent(new NavigationEvent(NavigationEvent.GO2_FAVORITE));
		}
		
		//dispatched the go2search event and moves the panel to the search portion
		private function onSearch(evt:MouseEvent):void
		{
			dispatchEvent(new NavigationEvent(NavigationEvent.GO2_SEARCH));
		}
		
		//on the enter frame the controler will move up and down with the direction
		private function onEnterFrame(evt:Event):void
		{
			gotoAndStop(currentFrame + _dir);
			if(_dir == -1 && currentFrame == 1)
			{
				removeEventListener(Event.ENTER_FRAME, onEnterFrame);
				_dir = -1;
			}
			this.multiControl.tabBtn.buttonMode = true;
		}
	}
}